package cn.phecda.boot.common.lang.util;

import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;

/**
 * <p> 环境配置属性查找 </p>
 *
 * @author : wanpinwei
 */
public interface EnvPropertyFinder {


    static String getString(Environment environment, String propertyName) {
        return environment.getProperty(propertyName);
    }

    static String getString(Environment environment, String propertyName, String defaultValue) {
        return environment.getProperty(propertyName, defaultValue);
    }

    static <T> T get(Environment environment, String propertyName, Class<T> targetType) {
        return environment.getProperty(propertyName, targetType);
    }

    static <T> T get(Environment environment, String propertyName, Class<T> targetType, T defaultValue) {
        return environment.getProperty(propertyName, targetType, defaultValue);
    }

    static boolean contains(Environment environment, String propertyName) {
        return environment.containsProperty(propertyName);
    }

    static boolean getBoolean(Environment environment, String propertyName, boolean defaultValue) {
        return get(environment, propertyName, Boolean.class, defaultValue);
    }

    static boolean getBoolean(Environment environment, String propertyName) {
        return get(environment, propertyName, Boolean.class, false);
    }

    static String getString(ConditionContext conditionContext, String propertyName) {
        return getString(conditionContext.getEnvironment(), propertyName);
    }

    static String getString(ConditionContext conditionContext, String propertyName, String defaultValue) {
        return getString(conditionContext.getEnvironment(), propertyName, defaultValue);
    }

    static <T> T get(ConditionContext conditionContext, String propertyName, Class<T> targetType) {
        return get(conditionContext.getEnvironment(), propertyName, targetType);
    }

    static <T> T get(ConditionContext conditionContext, String propertyName, Class<T> targetType, T defaultValue) {
        return get(conditionContext.getEnvironment(), propertyName, targetType, defaultValue);
    }

    static boolean contains(ConditionContext conditionContext, String propertyName) {
        return contains(conditionContext.getEnvironment(), propertyName);
    }

    static boolean getBoolean(ConditionContext conditionContext, String propertyName) {
        return get(conditionContext, propertyName, Boolean.class, false);
    }

    static boolean getBoolean(ConditionContext conditionContext, String propertyName, boolean defaultValue) {
        return get(conditionContext, propertyName, Boolean.class, defaultValue);
    }
}
